package com.hm.service.config.http;

import okhttp3.OkHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
public class HttpClientConfig {
    private static final Logger logger = LoggerFactory.getLogger(HttpClientConfig.class);

    //超时时间
    private static final int TimeOut = 120;

    @Bean(name = {"OkHttpClient"})
    public OkHttpClient okHttpClient() {
        logger.warn("OkHttpClient初始化了");
        return new OkHttpClient.Builder()//
                .connectTimeout(TimeOut, TimeUnit.SECONDS)//连接超时时间
                .readTimeout(TimeOut, TimeUnit.SECONDS)//读取超时时间
                .writeTimeout(TimeOut, TimeUnit.SECONDS)//写入超时时间
                .build();
    }


}
